package com.example.pubsub;

public class PubSubDemo {
    public static void main(String[] args) {
        EventManager eventManager = new EventManager("订单", "库存");

        EmailNotificationListener emailListener = new EmailNotificationListener("admin@example.com");
        SMSNotificationListener smsListener = new SMSNotificationListener("13800138000");

        eventManager.subscribe("订单", emailListener);
        eventManager.subscribe("订单", smsListener);
        eventManager.subscribe("库存", emailListener);

        // 测试发布订单事件
        eventManager.notify("订单", "新订单已创建");
        System.out.println("------------------------");

        // 测试发布库存事件
        eventManager.notify("库存", "库存不足预警");
        System.out.println("------------------------");

        // 取消订阅后测试
        eventManager.unsubscribe("订单", smsListener);
        eventManager.notify("订单", "订单已完成");
    }
}
